#include "sprite.h"
#include <cstring>

Sprite::Sprite()
{
    m_pictureRender = 0;

    m_physical = new Physical_Data();
    memset(m_physical,0,sizeof(Physical_Data));

    m_animationDelay = 0.25f;
    m_animationElapsed = 0.0f;

    m_isCollideable = true;
    m_isVisible = false;
    m_isActive = false;
    m_value = 0;

}

Sprite::~Sprite()
{
    delete m_physical;
    m_physical = 0;
}


void Sprite::jump_UP()
{
	if(m_physical->jumpState == JUMPSTATE_UP)
        return;
    m_physical->jumpState = JUMPSTATE_UP;
    m_physical->point.y -= 60.0f;

}

void Sprite::jump_DOWN()
{
	if(m_physical->jumpState == JUMPSTATE_DOWN)
        return;
    m_physical->jumpState = JUMPSTATE_DOWN;
    m_physical->point.y += 60.0f;
}

void Sprite::render()
{
    if(m_pictureRender == 0)
        return;

    if(m_isVisible == false)
        return;

    m_pictureRender->render(m_physical->point);
}

void Sprite::update(float deltaTime)
{
	if(!m_isActive) return;

	float dt = deltaTime;

    m_animationElapsed += dt;

    if(m_animationElapsed >= m_animationDelay)
    {
        m_pictureRender->update();
        m_animationElapsed = 0.0f;
    }

    m_physical->point.x = m_physical->point.x  + m_physical->velocity*dt;
}
